package cn.walls1717.ggkt.vod.api;

import cn.walls1717.ggkt.model.vod.Course;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.vo.vod.CourseQueryVo;
import cn.walls1717.ggkt.vod.service.CourseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 前台课程相关接口
 *
 * @author walls1717
 * @since 2022/7/20
 **/
@Api(tags = "前台课程相关接口")
@RestController
@RequestMapping("/api/vod/course")
public class CourseApiController {

    @Autowired
    private CourseService courseService;

    @ApiOperation("根据课程分类查询课程列表（分页）")
    @GetMapping("{subjectParentId}/{pageNum}/{pageSize}")
    public Result<Page<Course>> listPages(@PathVariable Long subjectParentId,
                                          @PathVariable Integer pageNum,
                                          @PathVariable Integer pageSize) {
        // 封装条件
        CourseQueryVo courseQueryVo = new CourseQueryVo();
        courseQueryVo.setSubjectParentId(subjectParentId);
        Page<Course> pageInfo = courseService.listPages(pageNum, pageSize, courseQueryVo);
        return Result.success(pageInfo);
    }

    @ApiOperation("根据课程id查询课程详情")
    @GetMapping("getInfo/{courseId}")
    public Result<Map<String, Object>> getCourseInfoById(@PathVariable Long courseId) {
        Map<String, Object> map = courseService.getCourseInfoById(courseId);
        return Result.success(map);
    }

    @ApiOperation("根据关键字查询课程")
    @GetMapping("inner/findByKeyword/{keyword}")
    public List<Course> innerListCoursesByKeyword(@PathVariable String keyword) {
        LambdaQueryWrapper<Course> lqw = new LambdaQueryWrapper<>();
        lqw.like(Course::getTitle, keyword);
        return courseService.list(lqw);
    }

    @ApiOperation("根据课程id查询课程信息")
    @GetMapping("inner/getById/{courseId}")
    public Course innerGetCourseById(@PathVariable Long courseId) {
        return courseService.getById(courseId);
    }
}
